const JWT = require('./JWT')
/**
 * 获取请求头带过来的token
 * @param req
 */
const getAuthorization = (req) => {
    if(!req.headers['authorization']) {
        return false
    }
    return req.headers['authorization'].replace('Bearer ', '').trim()
}

/**
 * 获取当前请求的用户信息
 * @param req { Object }
 * @return userData { Object }
 */

const getCurrentUserData = req => {
    return JWT.verify(getAuthorization(req))
}

module.exports = {
    getAuthorization,
    getCurrentUserData
}
